package ahblue.cn.tanzi.ui.person;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import ahblue.cn.tanzi.R;
import ahblue.cn.tanzi.data.source.ApiCallback;
import ahblue.cn.tanzi.data.source.RemoteRepository;
import ahblue.cn.tanzi.model.user.LoginResultModel;
import ahblue.cn.tanzi.model.user.MemberInfo;
import ahblue.cn.tanzi.ui.base.BaseActivity;
import ahblue.cn.tanzi.util.GlideApp;
import butterknife.BindView;
import butterknife.ButterKnife;

public class MemberInfoActivity extends BaseActivity {

    public final static String ARG_USER_ID = "ARG_USER_ID";

    @BindView(R.id.iv_avatar)
    ImageView mImageViewAvatar;
    @BindView(R.id.tv_username)
    TextView mTextViewUserName;

    @BindView(R.id.tv_count)
    TextView mTextViewCount;

    @BindView(R.id.tv_noaudit)
    TextView mTextViewNoAudit;  // 未认证
    @BindView(R.id.tv_realaudit)
    TextView mTextViewRealAudit;  // 实名认证

    private LoginResultModel mLoginResultModel;
    private Long mUserId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal_info_v3);

        ButterKnife.bind(this);

        Intent intent = getIntent();
        mUserId = intent.getLongExtra(ARG_USER_ID, 0);

        initData();
    }

    private void initData() {
        mLoginResultModel = LoginResultModel.getUserModel(this, LoginResultModel.class);

        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.getMemberInfo(mLoginResultModel.token, mUserId, new ApiCallback<MemberInfo>() {
            @Override
            public void onSuccess(MemberInfo data) {
                update(data);
            }

            @Override
            public void onFailed(String errorMsg) {

            }
        });
    }

    private void update(MemberInfo memberInfo) {
        mTextViewUserName.setText(memberInfo.member_name);
        GlideApp.with(mImageViewAvatar).load(memberInfo.member_avatar).error(R.drawable.user_default_avatar).into(mImageViewAvatar);

        mTextViewNoAudit.setVisibility(View.VISIBLE);

        mTextViewCount.setText("关注课程: 0 | 关注圈子: " + memberInfo.circle_id.size());
    }
}
